package com.bkq.viettravel;

import java.util.ArrayList;
import java.util.List;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.view.View.OnClickListener;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.Toast;


public class VietTravelActivity extends MapActivity {
	
	MapController mControl;
	GeoPoint point;
	MapView mapview;
	private static final int latitudeDN = 16050571;
	private static final int longitudeDN = 108204897;
	
	Button search;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);
        mapview = (MapView) findViewById(R.id.myMap);
      //  mapview.setBuiltInZoomControls(true);  
        point = new GeoPoint(latitudeDN, longitudeDN);
        mControl = mapview.getController();
        mControl.animateTo(point);
        mControl.setZoom(7);
        List<Overlay> mapOverlays = mapview.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.map_pin);
		CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(drawable, this);
		
		GeoPoint point = new GeoPoint(latitudeDN, longitudeDN);
		OverlayItem overlayitem = new OverlayItem(point, "Hello", "You're in Da Nang, Viet Nam!");
		itemizedOverlay.addOverlay(overlayitem);
		mapOverlays.add(itemizedOverlay);
        search = (Button) findViewById(R.id.home_Bnt_search);
        search.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent i = new Intent(VietTravelActivity.this,ListTravel.class);
				startActivity(i); 
			}
		});
       
    }

	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}
	 class CustomItemizedOverlay extends ItemizedOverlay<OverlayItem> {
			private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
			private Context context;
			public CustomItemizedOverlay(Drawable defaultMarker, Context context) {
				  //this(defaultMarker);
				  super(boundCenterBottom(defaultMarker));
				  this.context = context;
			}
			@Override
			protected OverlayItem createItem(int i) {
				return mapOverlays.get(i);
			}
			@Override
			public int size() {
				return mapOverlays.size();
			}
			@Override
			protected boolean onTap(int index) {
				OverlayItem item = mapOverlays.get(index);
				AlertDialog.Builder dialog = new AlertDialog.Builder(context);
				dialog.setTitle(item.getTitle());
				dialog.setMessage(item.getSnippet());
				dialog.setPositiveButton("Login", new DialogInterface.OnClickListener() {
					@Override
					public void onClick(DialogInterface dialog, int which) {
						// TODO Auto-generated method stub
						startActivity(new Intent(VietTravelActivity.this,ListTravel.class));
					}
				});
				dialog.show();
				return true;
			}
			
			public void addOverlay(OverlayItem overlay) {
				mapOverlays.add(overlay);
			    this.populate();
			}
		}
}